using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Comdiv.Application;
using Comdiv.Conversations;
using Comdiv.Extensibility.Boo;
using Comdiv.Extensions;
using Comdiv.Inversion;
using Comdiv.IO;
using Comdiv.Logging;
using Comdiv.Model;
using Comdiv.Model.Interfaces;
using Comdiv.Persistence;
using Comdiv.Security;
using Comdiv.Security.Acl;
using NUnit.Framework;

namespace Comdiv.Boo.Test{
    [TestFixture]
    public class BasicBooEvaluation{
        #region Setup/Teardown

        [SetUp]
        public void Setup(){
            root = "BasicBooEvaluation_test".prepareTemporaryDirectory();
            File.WriteAllText(Path.Combine(root, "test.boo"), @"test = ""Test""");
            File.WriteAllText(Path.Combine(root, "inc.boo"), "test = \"Test2\"\r\n#include test");
        }

        #endregion

        private string root;


        [Test]
        public void FullFileNameTest(){
            Assert.AreEqual("Test", BooEval.Default.EvaluateFile(Path.Combine(root, "test.boo")));
        }

        [Test]
        public void IncludeTest(){
            BooEval.Default.RootDirectory = root;
            Assert.AreEqual("Test", BooEval.Default.EvaluateFile("inc"));
        }

        [Test]
        public void PartialNameTest(){
            BooEval.Default.RootDirectory = root;
            Assert.AreEqual("Test", BooEval.Default.EvaluateFile("test"));
        }

        [Test]
        public void RelativeNameTest(){
            BooEval.Default.RootDirectory = root;
            Assert.AreEqual("Test", BooEval.Default.EvaluateFile("test.boo"));
        }

        [Test]
        public void SimpleExpressionReturnValue(){
            var i = new Random().Next(1000);
            Assert.AreEqual(i, BooEval.Default.Evaluate(i.ToString()));
        }

        [Test]
        public void SimpleGlobalsTest(){
            var i = new Random().Next(1000);
            var s = "var" + i;
            Assert.AreEqual(i, BooEval.Default.Evaluate(s, new Dictionary<string, object>{{s, i}}));
        }
    }
}